//  this library.
import 'package:hktk_app/ienum/home/column_type_enum.dart';
import 'package:hktk_app/model/practice/practice_model.dart';
import 'package:hktk_app/model/practice/practice_question_model.dart';
import 'package:hktk_app/model/subject/question_collection_model.dart';

/// 试卷交卷返回数据
class SubmitPaperModel {
  // 试卷记录
  PaperRecords? paperRecords;

  // 试卷试题结构，或者试题集合
  QuestionCollectionModel? collectStructure;

  // 试卷做题记录信息
  Records? records;

  SubmitPaperModel({
    this.paperRecords,
    this.collectStructure,
    this.records,
  });

  SubmitPaperModel.fromJson(Map<String, dynamic> json) {
    paperRecords = json["paperRecords"] != null
        ? PaperRecords.fromJson(json["paperRecords"])
        : null;
    collectStructure = json["collectStructure"] != null
        ? QuestionCollectionModel.fromJson(json["collectStructure"])
        : null;
    records =
    json['records'] != null ? Records.fromJson(json['records']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    if (paperRecords != null) {
      data["paperRecords"] = paperRecords!.toJson();
    }
    if (collectStructure != null) {
      data["collectStructure"] = collectStructure!.toJson();
    }
    if (records != null) {
      data['records'] = records!.toJson();
    }
    return data;
  }
}

class PaperRecords {
  String? createdTime;
  String? modifyTime;
  String? id;

  // 试卷id
  String? paperId;

  // 试卷类型
  ColumnTypeEnum? type;

  // 用户id
  String? userId;

  // 记录名称
  String? name;

  // 科目id
  int? categoryId;

  // 考试id
  String? examId;

  // 做题时间
  int? seconds;

  // 是否通过
  bool? hp;

  // 得分数
  double? score;

  // 总分数
  double? allScore;

  // 通过分数
  double? passScore;

  // 试卷总题数
  int? qcount;

  // 做题数目
  int? doCount;

  // 试卷错题数
  int? errorCount;

  // 开始时间
  String? startTime;

  // 结束时间
  String? endTime;

  // 试卷完成次数
  int? completeCount;

  // 考试时长
  int? examTime;

  // 科目名称
  String? categoryName;

  // 考试名称
  String? examName;

  // 行业id
  String? industryId;

  // 行业名称
  String? industryName;

  List<ContentPractice>? content;
  bool? haveFinish;

  PaperRecords({
    this.createdTime,
    this.modifyTime,
    this.id,
    this.paperId,
    this.type,
    this.userId,
    this.name,
    this.categoryId,
    this.examId,
    this.seconds,
    this.hp,
    this.score,
    this.allScore,
    this.passScore,
    this.qcount,
    this.doCount,
    this.errorCount,
    this.startTime,
    this.endTime,
    this.completeCount,
    this.examTime,
    this.categoryName,
    this.examName,
    this.industryId,
    this.industryName,
    this.content,
    this.haveFinish,
  });

  PaperRecords.fromJson(Map<String, dynamic> json) {
    createdTime = json['createdTime'];
    modifyTime = json['modifyTime'];
    id = json['id'];
    paperId = json['paperId'];
    if (json["type"] != null) {
      type = ColumnTypeEnum.getColumnType(json['type']);
    }
    userId = json['userId'];
    name = json['name'];
    categoryId = json['categoryId'];
    examId = json['examId'];
    seconds = json['seconds'];
    hp = json['hp'];
    if (json["score"] != null) {
      score = double.parse(json['score'].toString());
    }
    if (json["allScore"] != null) {
      allScore = double.parse(json['allScore'].toString());
    }
    if (json["passScore"] != null) {
      passScore = double.parse(json['passScore'].toString());
    }
    qcount = json['qcount'];
    doCount = json['doCount'];
    errorCount = json['errorCount'];
    startTime = json['startTime'];
    endTime = json['endTime'];
    completeCount = json['completeCount'];
    examTime = json['examTime'];
    categoryName = json['categoryName'];
    examName = json['examName'];
    industryId = json['industryId'];
    industryName = json['industryName'];
    if (json['content'] != null) {
      content = <ContentPractice>[];
      json['content'].forEach((v) {
        content!.add(ContentPractice.fromJson(v));
      });
    }
    haveFinish = json['haveFinish'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['createdTime'] = createdTime;
    data['modifyTime'] = modifyTime;
    data['id'] = id;
    data['paperId'] = paperId;
    if (type != null) {
      data['type'] = type!.desc;
    }
    data['userId'] = userId;
    data['name'] = name;
    data['categoryId'] = categoryId;
    data['examId'] = examId;
    data['seconds'] = seconds;
    data['hp'] = hp;
    data['score'] = score;
    data['allScore'] = allScore;
    data['passScore'] = passScore;
    data['qcount'] = qcount;
    data['doCount'] = doCount;
    data['errorCount'] = errorCount;
    data['startTime'] = startTime;
    data['endTime'] = endTime;
    data['completeCount'] = completeCount;
    data['examTime'] = examTime;
    data['categoryName'] = categoryName;
    data['examName'] = examName;
    data['industryId'] = industryId;
    data['industryName'] = industryName;
    if (content != null) {
      data['content'] = content!.map((v) => v.toJson()).toList();
    }
    data['haveFinish'] = haveFinish;
    return data;
  }
}

class Records {
  Map<String, RecordModel>? data;

  Records({this.data});

  Records.fromJson(Map<String, dynamic> json) {
    if (json["data"] != null) {
      var jsonData = json["data"];
      if (jsonData is Map<String, dynamic>) {
        data = <String, RecordModel>{};
        jsonData.forEach((key, value) {
          data![key] = RecordModel.fromJson(value);
        });
      }
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    if (this.data != null) {
      Map<String, dynamic> map = {};
      this.data!.forEach((key, value) {
        map[key] = value.toJson();
      });
      data['data'] = map;
    }
    return data;
  }
}
